package cn.jari.erp.inventory.patches

import com.csicit.ace.api.BatchElementEvent
import cn.jari.erp.inventory.ServicePatchGroup
import com.csicit.ace.patcher.PatchProvider
import com.csicit.ace.utils.AceAppContext
import com.csicit.ace.api.modeler.dto.AggregateDefinitionReference
import com.csicit.ace.api.modeler.dto.DtoDefinitionReference
import com.csicit.ace.api.modeler.dto.EntityDefinitionReference
import com.csicit.ace.api.modeler.dto.QueryDefinitionReference
import com.csicit.ace.api.modeler.enums.CollectionType
import com.csicit.ace.api.modeler.enums.LockType
import com.csicit.ace.api.modeler.enums.MapKeyDataType
import com.csicit.ace.api.modeler.enums.ParameterDataType
import com.csicit.ace.api.modeler.enums.QueryHttpMethod
import com.csicit.ace.api.modeler.enums.QueryResultCollectionType
import com.csicit.ace.api.modeler.enums.RequestParamBindingType
import com.csicit.ace.api.modeler.enums.ReturnDataType
import com.csicit.ace.api.modeler.event.ModelerBatchEvent
import com.csicit.ace.api.modeler.event.query.CreateQueryDefinitionEvent
import com.csicit.ace.api.modeler.event.query.CreateQueryParamDefinitionEvent
import java.util.Set
import org.axonframework.eventhandling.gateway.EventGateway
import org.springframework.stereotype.Component

/*
 * 警告：代码由鲲舟平台生成，请勿手动修改。
 * Warn: This class file is generated by JARI-ACE platform, please do not modify manually。
 */

/**
 * inventory-service的0.1.0-SNAPSHOT-3版升级补丁
 *
 * @author JARI-ACE
 */
@Component
@AceAppContext
open class Patch_0_1_0_SNAPSHOT_3(val eventGateway: EventGateway) : PatchProvider {
    override fun getGroup(): Class<*> {
        return ServicePatchGroup::class.java
    }

    override fun getPatchVersion(): Long {
        return 549755813891
    }

    override fun getProductVersion(): String {
        return "0.1.0-SNAPSHOT-3"
    }

    override fun executePatch() {
        doExecuteModelerBatchEvent0()
    }

    fun doExecuteModelerBatchEvent0() {
        val modelerBatchEvent = ArrayList<BatchElementEvent>()
        modelerBatchEvent.add(CreateQueryDefinitionEvent.builder()
            .id("8nkFbruJIsN")
            .dataVersion(0)
            .appName("jari-erp")
            .serviceName("inventory-service")
            .aggregate(AggregateDefinitionReference.builder()
                .id("8nkFbruJIsN")
                .releaseSource("8716")
                .sourceId("5uFzovh2zo5")
                .appName("jari-erp")
                .serviceName("inventory-service")
                .name("InventoryCategory")
                .build())
            .name("getByName")
            .openToClient(true)
            .httpMethod(QueryHttpMethod.GET)
            .noAuthRequired(false)
            .roleName("")
            .requestPath("")
            .description("根据名称获取")
            .returnType(ReturnDataType.ENTITY)
            .returnDto(DtoDefinitionReference.builder()
                .id("8nkFbruJIsO")
                .sourceId("5uFzovh2zo6")
                .releaseSource("8716")
                .name("InventoryCategoryReference")
                .caption("entity.inventoryCategory引用")
                .flatten(false)
                .appName("jari-erp")
                .serviceName("inventory-service")
                .asInterface(false)
                .build())
            .collectionType(QueryResultCollectionType.NONE)
            .returnEnum(null)
            .mapKeyEnum(null)
            .mapKeyDataType(MapKeyDataType.STRING)
            .lockType(LockType.NONE)
            .queryText("select new dto(a) from InventoryCategory a")
            .dynamicQuery(false)
            .queryEntity(EntityDefinitionReference.builder()
                .id("8nkFbruJIsN")
                .releaseSource("8716")
                .sourceId("5uFzovh2zo5")
                .dataVersion(0)
                .name("InventoryCategory")
                .caption("存货类别")
                .tableName("iv_inventory_category")
                .build())
            .rawSql(false)
            .graphProperties(setOf())
            .releaseSource("8716")
            .sourceId("8nkFbruJIsN")
            .build())
        modelerBatchEvent.add(CreateQueryParamDefinitionEvent.builder()
            .id("8nkFbruJIsN")
            .dataVersion(0)
            .sourceId("8nkFbruJIsN")
            .releaseSource("8716")
            .query(QueryDefinitionReference.builder()
                .id("8nkFbruJIsN")
                .releaseSource("8716")
                .sourceId("8nkFbruJIsN")
                .appName("jari-erp")
                .serviceName("inventory-service")
                .name("getByName")
                .build())
            .name("name")
            .sortIndex(1)
            .notNull(true)
            .bindingType(RequestParamBindingType.PATH_VARIABLE)
            .dataType(ParameterDataType.STRING)
            .dto(null)
            .collectionType(CollectionType.NONE)
            .mapKeyDataType(null)
            .enumType(null)
            .mapKeyEnum(null)
            .description("名称")
            .build())
        eventGateway.publish(ModelerBatchEvent.builder()
                                          .events(modelerBatchEvent)
                                          .build())
    }

    override fun getPatchSource(): String {
        return "c321"
    }
}

